<div class="bc-info" data-port='http://api.hongyanche.com/user/info' cache='user'>
	<password info=d class='weui-cells__title' style='display: block;text-align: right;'><a mute href='#password_reset'>忘记密码？</a></password>
	<password info=d class='weui-cells' style='display: block;'>
		<div class='weui-cell' id='password-old-container'>
			<div class='weui-cell__hd' style='width:70px;'>旧密码</div>
			<div class='weui-cell__bd'><form onsubmit="$('#password-submit').trigger('click')"><input type='password' id="password-old-input" class='weui-input' placeholder="请输入旧密码"/></form></div>
		</div>
	</password>
	<div class='weui-cells__title'>
		新密码 8-32位 必须包含字母与数字
	</div>
	<div class='weui-cells'>
		<div class='weui-cell'>
			<div class='weui-cell__hd' style='width:70px;'>新密码</div>
			<div class='weui-cell__bd'><form onsubmit="$('#password-submit').trigger('click')"><input type='password' id="password-new-input" class='weui-input' placeholder="输入新密码"/></form></div>
		</div>
		<div class='weui-cell'>
			<div class='weui-cell__hd' style='width:70px;'>重复密码</div>
			<div class='weui-cell__bd'><form onsubmit="$('#password-submit').trigger('click')"><input type='password' id="password-new-input-repeat" class='weui-input' placeholder="请重复密码"/></form></div>
		</div>
		<div class='weui-cell' style='display: none;' id="password-vcode-cell">
			<div class='weui-cell__hd' style='width:70px;'>图形码</div>
			<div class='weui-cell__bd'><form onsubmit="$('#password-submit').trigger('click')"><input type='email' id="password-vcode" class='login-vcode-input weui-input' name='vcode' placeholder="输入图形码" /></form></div>
			<div class='weui-cell__ft'><img class='vcode'/></div>
		</div>
	</div>
	<div id="password-error" style='height:18px;padding:3px 3px 3px 10px;color:maroon;'></div>
	<div class='weui-btn-area'>
		<div class='weui-btn weui-btn_primary' id="password-submit">提交修改</div>
	</div>
</div>
<script>
	passwordInit = function(){
		var o = $("#password-old-input");
		var n = $("#password-new-input");
		var r = $("#password-new-input-repeat");
		var v = $("#password-vcode");
		var err = $("#password-error");
        var password_reg = /((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}$/;
		n.focus();
		POST.init("#password-submit",{
			stop:function(){
                var password = o.val();
                if(!password_reg.test(password)){
                    var errormsg = '请输入正确的密码(大小写字母+数字8-16位的组合)';
                    err.html(errormsg);
                    alert(errormsg,' ',1);
                    p.focus();
                    return true;
                }
				if(n.val().length < 8){
					err.html('请输入正确格式的密码');
					n.focus();
					return true;
				}
				if( n.val() != r.val() ){
					err.html('重复密码不匹配');
					r.focus();
					return true;
				}
			},
			url:"/user/password_set",
			text:"修改密码",
			input:function(){
				return {password:n.val(),password_old:o.val(),vcode:v.val()}
			},
			success:function(){
				err.html('');
				$("#password-vcode-cell").hide();
				$(document).trigger('password-success-set')
			},
			error:function(e,res){
				var errormsg = res.errormsg;
				switch(errormsg){
					case "vcode error":
					$("#password-vcode-cell").show();
					$(".vcode").addClass("active")
					$(".vcode").attr('src','/vcode')
					$("#password-vcode").val('')
					$("#password-vcode").focus();
					break;
					case "old password error":
					$("#password-old-container").fadeIn();
					o.focus();
					break;
					default:
					$("#password-vcode-cell").hide();
					break;
				}
				err.html(this.msg[errormsg] || errormsg);
			},
			msg:{
				"old password same":"新旧密码不能一致",
				"vcode error":"图形码不正确",
				"password incorrect":"密码格式不正确",
				"old password error":"旧密码不正确",
			}
		})
	}
	passwordInit();
</script>